package com.example.demo.service;

import com.example.demo.dao.businessMapper;
import com.example.demo.pojo.Business;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class BusinessService {
    @Autowired
    businessMapper businessmapper;

    @Transactional(readOnly = true)
    public List<Business> selectAllBusiness(){
        return businessmapper.selectAllBusiness();
    }

    @Transactional(readOnly = true)
    public Business selectBusinessById(int id){
        return businessmapper.selectBusinessByid(id);
    }

    @Transactional(timeout =10,rollbackFor = Exception.class)
    public void addBusiness(Business business){
        businessmapper.addBusiness(business);
    }

    @Transactional(timeout =10,rollbackFor = Exception.class)
    public void updateBusiness(Business business){
        businessmapper.updateBusiness(business);
    }

    @Transactional(timeout =10,rollbackFor = Exception.class)
    public void deleteBusiness(int id){
        businessmapper.deleteBusiness(id);
    }

    @Transactional(timeout =10,rollbackFor = Exception.class)
    public void changeAllBusiness(List<Business> businesslist){
        for(Business business:businesslist){
            businessmapper.updateBusiness(business);
        }
    }
    @Transactional(readOnly = true)
    public int bus_num(){
        return businessmapper.bus_num();
    }

    @Transactional(timeout = 10, rollbackFor = Exception.class)
    public void call_checkbusiness(int business_id) {
        businessmapper.call_checkbusiness(business_id);
    }
}
